package org.cmg.study.spring;

import org.aspectj.lang.annotation.*;

/**
 * @author CMG
 * @version 1.0
 * @cLassName Logging
 * @description
 * @date 2021/9/1 10:51
 **/
@Aspect
public class Logging {
    /**
     * 定义切入点
     */
    @Pointcut("execution(* org.cmg.study.spring.*.*(..))")
    private void selectAll(){
    }

    /**
     * 后置通知
     */
    @Before("selectAll()")
    public void beforeAdvice(){
        System.out.println("前置通知");
    }

    /**
     * 后置通知
     */
    @After("selectAll()")
    public void afterAdvice(){
        System.out.println("后置通知");
    }

    /**
     * 返回后通知
     * @param retVal
     */
    @AfterReturning(pointcut = "selectAll()", returning = "retVal")
    public void afterReturningAdvice(Object retVal){
        System.out.println("返回值为：" + retVal.toString());
    }

    /**
     * 抛出异常通知
     * @param ex
     */
    @AfterThrowing(pointcut = "selectAll()", throwing = "ex")
    public void afterThrowingAdvice(IllegalArgumentException ex){
        System.out.println("这里的异常为：" + ex.toString());
    }

}
